from rest_framework.generics import ListAPIView
from rest_framework.views import APIView
from recruit.models import City
from rest_framework.response import Response
from rest_framework.generics import GenericAPIView
from recruit.serializers.city_serializer import CityModelSerializer


# class CityView(APIView):
#
#     def get(self,request):
#
#         try:
#             hot_cities = City.objects.filter(ishot=1)
#         except Exception as e:
#             return Response
#
#         hot_city_list = []
#         for hot_city in hot_cities:
#             hot_city_list.append({
#                 'id':hot_city.id,
#                 'name':hot_city.name,
#                 'ishot':hot_city.ishot
#             })
#
#         return Response(hot_city_list)

class CityView(GenericAPIView):
    """热门城市 接口"""

    queryset = City.objects.filter(ishot=1)
    serializer_class = CityModelSerializer

    def get(self,request):
        query_hot_city = self.get_queryset()
        seria_hot_city = self.get_serializer(instance=query_hot_city,many=True)

        return Response(seria_hot_city.data)


